﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RunningSimulation.SignalData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.RunningSimulation;

internal class SignalData
{
  private const double PLC_VAL_CMP_EPS = 1E-05;
  private ITxPlcSignal m_signal;
  private bool BooleanValue;
  private ushort ByteValue;
  private ushort WordValue;
  private uint DWordValue;
  private short IntValue;
  private int DIntValue;
  private float RealValue;
  private double LRealValue;
  private TxPlcHardwareType m_type;

  public SignalData(ITxPlcSignal signal, TxPlcHardwareType hwType)
  {
    this.m_signal = signal;
    this.m_type = hwType;
  }

  public ITxPlcSignal Signal => this.m_signal;

  public TxPlcHardwareType Type => this.m_type;

  public bool isSignalValueChanged()
  {
    return this.m_type != 6 ? (this.m_type != 11 ? !this.GetValue().Equals(this.Signal.Value.GetValueByType(this.Type)) : Math.Abs((double) this.GetValue() - (double) this.Signal.Value.GetValueByType(this.Type)) > 1E-05) : (double) Math.Abs((float) this.GetValue() - (float) this.Signal.Value.GetValueByType(this.Type)) > 1E-05;
  }

  public object GetValue()
  {
    switch ((int) this.m_type)
    {
      case 0:
        return (object) this.BooleanValue;
      case 1:
        return (object) this.ByteValue;
      case 2:
        return (object) this.WordValue;
      case 3:
        return (object) this.DWordValue;
      case 4:
        return (object) this.IntValue;
      case 5:
        return (object) this.DIntValue;
      case 6:
        return (object) this.RealValue;
      case 11:
        return (object) this.LRealValue;
      default:
        return (object) null;
    }
  }

  public void SetValue(object value)
  {
    switch ((int) this.m_type)
    {
      case 0:
        this.BooleanValue = (bool) value;
        break;
      case 1:
        this.ByteValue = (ushort) value;
        break;
      case 2:
        this.WordValue = (ushort) value;
        break;
      case 3:
        this.DWordValue = (uint) value;
        break;
      case 4:
        this.IntValue = (short) value;
        break;
      case 5:
        this.DIntValue = (int) value;
        break;
      case 6:
        this.RealValue = (float) value;
        break;
      case 11:
        this.LRealValue = (double) value;
        break;
    }
  }
}
